package com.examsystem.filter;

import com.alibaba.fastjson.JSON;
import com.examsystem.pojo.vo.Result;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.AuthenticationEntryPoint;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
/**
 * @author fire'ge
 */
@Component
public class AuthticationEntryPointImpl implements AuthenticationEntryPoint {
    @Override
    public void commence(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, AuthenticationException e) throws IOException, ServletException {
        httpServletResponse.setContentType("application/json;charset:utf-8");
        httpServletResponse.getWriter().println(JSON.toJSONString(Result.fail(e.getMessage())));
        e.printStackTrace();
    }
}
